﻿using System;

namespace SPFluid.Core.Validation
{
    internal class ExceptionHandler<T> : IExceptionHandler
    {
        private readonly IArgument<T> argument;

        public ExceptionHandler(IArgument<T> argument)
        {
            this.argument = argument;
        }

        public void ThrowArgumentException(string message)
        {
            if (string.IsNullOrEmpty(this.argument.Name))
            {
                throw new ArgumentException(message);
            }

            throw new ArgumentException(message, this.argument.Name);
        }

        public void ThrowArgumentNullException()
        {
            if (string.IsNullOrEmpty(this.argument.Name))
            {
                throw new ArgumentNullException();
            }

            throw new ArgumentNullException(this.argument.Name);
        }

        public void ThrowArgumentOutOfRangeException()
        {
            if (string.IsNullOrEmpty(this.argument.Name))
            {
                throw new ArgumentOutOfRangeException();
            }

            throw new ArgumentOutOfRangeException(this.argument.Name);
        }
    }
}